<html>
<head><title>Download on my freebox</title></head>
<script src="js/fbdownload.js"></script>
<script type="text/javascript">

var imgok = "img/ok.png";
var imgnok = "img/nok.png";

function checkPassword(){
  var pass = localStorage["freebox_password"];
  var ok = login( pass );
  var select = document.getElementById("Check");
  var err = document.getElementById("err");
  console.log(err);
  if (ok.result) {
  	select.src = imgok;
  	err.innerText="";
  }
  else {
  	select.src = imgnok;
  	err.innerText=ok.error;
  	}
}

function save_options() {
  var select = document.getElementById("password");
  localStorage["freebox_password"] = select.value;
  
  checkPassword();
  
  // Update status to let user know options were saved.
  var status = document.getElementById("status");
  status.innerHTML = "Options Saved.";
  setTimeout(function() {
    status.innerHTML = "";
  }, 750);
}

// Restores select box state to saved value from localStorage.
function restore_options() {
  var pass = localStorage["freebox_password"];
  if (!pass) {
    return;
  }
  var select = document.getElementById("password");
  select.value = pass;
  checkPassword();
  
}

</script>

<body onload="restore_options()">
	<center>
		<table>
			<tr>
				<td>
					<img src="img/down.png"  width="32"/> 
				</td>
				<td>
					Donwload on my freebox
				</td>
			</tr>
		</table>
Mot de passe:
<input type="password"  name="passwd" id="password"> 
<img id="Check" name="Check" width="16"/> 
<div id="err"/></div>
<br>
<button onclick="save_options()">Save</button>
<div id="status"/></div>
</center>

</body>
</html>